<?php


namespace sm_shop\api\member;
use sm_shop\controller;


use sm_shop\model\customerModel;

class member extends controller{

    /**
     * 获取登录状态
     */
    public function status(){


        $res= [
            'status'=>0
        ];
        global $_W, $_GPC;
//        print_r( $_SESSION );
        if( !empty($_W['member']['uid'] ) && !empty($_W['customer'] ) ){
            $res['customer_id'] = $_W['customer']['id'];
            $fans = mc_fansinfo( $_W['member']['uid'] );
            $res['nickname'] = !empty($fans['nickname'])?$fans['nickname']:'';
            $res['avatar'] = !empty($fans['avatar'])?$fans['avatar']:'';
        }else{
            $res['status'] = 1;
            $res['description'] = '没有登录';
        }

        echo json_encode( $res );
    }

    /**
     * 返回微擎自带的积分等资产,以及用户组， uni_member表uid
     */
    public function assets(){

        global $_W;
        //  获取积分的名称 table:uni_settings
        //  获取积分 table:mc_members
        $json = [
            'credit'=>[],
            'group'=>[
                'groupid'=>0,
                'groupname'=>'',
            ],
        ];
        $creditnames = $_W['account']['setting']['creditnames'];

        foreach( $creditnames as $key => &$item ){

            $item['value'] = $_W['member'][$key] ? $_W['member'][$key] : 0;

        }

        $json['member_uid'] = $_W['member']['uid'];
        $json['credit'] = $creditnames;
        $json['group'] = [
            'id'=>$_W['member']['groupid'],
            'name'=>$_W['member']['groupname']
        ];

        echo json_encode( $json );

    }
}